package com.fund.main.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fund.main.base.BaseController;
import com.fund.main.entity.TOptional;
import com.fund.main.service.TOptionalService;
import com.fund.security.base.BaseAppController;
import com.fund.utils.AppResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 基金自选接口
 *
 * @author makejava
 * @since 2023-02-14 13:40:58
 */
@RestController
@RequestMapping("/tOptional")
public class TOptionalController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TOptionalService tOptionalService;

    /**
     * 分页查询所有数据
     *
     * @param page      分页对象
     * @param tOptional 查询实体
     * @return 所有数据
     */
    @GetMapping("/page")
    public AppResponse<Page<TOptional>> selectAll(Page<TOptional> page, TOptional tOptional) {
        return AppResponse.ok(this.tOptionalService.getPage(page, tOptional));
    }

    @GetMapping("/pageLike")
    public AppResponse<Page<TOptional>> selectAllLike(Page<TOptional> page, TOptional tOptional) {
        return AppResponse.ok(this.tOptionalService.getPageLikeName(page, tOptional));
    }

    /**
     * 查询所有
     *
     * @param tOptional t身体记录
     * @return {@link AppResponse}<{@link List}<{@link TOptional}>>
     */
    @GetMapping("/queryAll")
    public AppResponse<List<TOptional>> queryAll(TOptional tOptional) {
        return AppResponse.ok(this.tOptionalService.queryAll(tOptional));
    }


    /**
     * 新增数据
     *
     * @param tOptional 实体对象
     * @return 新增结果
     */
    @PostMapping("/add")
    public AppResponse<Boolean> insert(@RequestBody TOptional tOptional) {
        return AppResponse.ok(this.tOptionalService.insertOne(tOptional));
    }

    /**
     * 修改数据
     *
     * @param tOptional 实体对象
     * @return 修改结果
     */
    @PutMapping("/update")
    public AppResponse<Boolean> update(@RequestBody TOptional tOptional) {
        return AppResponse.ok(this.tOptionalService.updateOneById(tOptional));
    }

    /**
     * 删除数据  直接?idList=1&idList=2  拼接式传参
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/deleteList")
    public AppResponse<Boolean> delete(@RequestParam("idList") List<String> idList) {
        return AppResponse.ok(this.tOptionalService.deleteListByIds(idList));
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public AppResponse<TOptional> selectOne(@PathVariable String id) {
        return AppResponse.ok(this.tOptionalService.getOneById(id));
    }
}

